/**
 * Generali Solutions d'assurances - Tous droits réservés &copy; 2007 - 2010
 */
package fr.generali.accueilclient.resumesuspens.builder;

import java.util.ArrayList;
import java.util.List;

import fr.generali.accueilclient.resume.suspens.builder.IOperationBuilder;
import fr.generali.accueilclient.resume.suspens.builder.IResumeSuspensBuilder;
import fr.generali.accueilclient.resume.suspens.builder.OperationDirector;
import fr.generali.accueilclient.resume.suspens.om.IOperation;
import fr.generali.accueilclient.resume.suspens.om.IResumeSuspens;
import fr.generali.accueilclient.resume.suspens.om.impl.DTOResumeSuspens;
import fr.generali.souscriptiongestion.dommages.tosca.rechercheroperationscontratclient.ctr.operationscontrat.DTOOperationContrat;
import fr.generali.souscriptiongestion.dommages.tosca.rechercheroperationscontratclient.reponse.DTOReponse;

/**
 * @author Holmes Kelly
 */
public class DTOReponse2ResumeSuspensBuilder implements IResumeSuspensBuilder {

    /**
     *
     */
    private IResumeSuspens resume;

    /**
     *
     */
    private DTOReponse input;

    /**
     * @param input DTOReponse
     */
    public DTOReponse2ResumeSuspensBuilder(DTOReponse input) {
        this.input = input;
        resume = new DTOResumeSuspens();
    }

    /**
     * {@inheritDoc}
     */
    public void buildNombreOperationsContratActives() {
        resume.setNombreOperationsContratActives(input.getNombreOperationsContratActives());
    }

    /**
     * {@inheritDoc}
     */
    public void buildNombreToutesOperationsContrat() {
        resume.setNombreToutesOperationsContrat(input.getNombreToutesOperationsContrat());
    }

    /**
     * {@inheritDoc}
     */
    public void buildOperations() {

        if (input.getNombreOperationsContratActives().intValue() > 0) {

            List<IOperation> listOperations = new ArrayList<IOperation>();

            for (DTOOperationContrat operationContrat : input.getOperationsContrat()) {

                IOperationBuilder operationBuilder = new DTOOperationContrat2OperationBuilder(operationContrat);
                OperationDirector operationDirector = new OperationDirector(operationBuilder);

                operationDirector.constructOperation();

                IOperation operation = operationDirector.getOperation();
                if (operation != null) {
                    operation.setNumeroClient(operationContrat.getContrat()
                                    .getSouscripteurContrat().getSouscripteur().getIdentifiantPersonne());
                }

                listOperations.add(operation);

            }

            resume.setOperations(listOperations);

        }

    }

    /**
     * {@inheritDoc}
     */
    public IResumeSuspens getResumeSuspens() {

        return resume;
    }

}
